package cn.yinyu.queue.module.ecg.dal.mysql.checktype;

import java.util.*;

import cn.yinyu.queue.framework.common.pojo.PageResult;
import cn.yinyu.queue.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.yinyu.queue.framework.mybatis.core.mapper.BaseMapperX;
import cn.yinyu.queue.module.ecg.dal.dataobject.checktype.CheckTypeDO;
import org.apache.ibatis.annotations.*;
import cn.yinyu.queue.module.ecg.controller.admin.checktype.vo.*;

/**
 * 检查类型 Mapper
 *
 * @author majianbo
 */
@Mapper
public interface CheckTypeMapper extends BaseMapperX<CheckTypeDO> {

    default PageResult<CheckTypeDO> selectPage(CheckTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CheckTypeDO>()
                .likeIfPresent(CheckTypeDO::getName, reqVO.getName())
                .eqIfPresent(CheckTypeDO::getValue, reqVO.getValue())
                .eqIfPresent(CheckTypeDO::getReadyNum, reqVO.getReadyNum())
                .betweenIfPresent(CheckTypeDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CheckTypeDO::getNeedDevReady, reqVO.getNeedDevReady())
                .eqIfPresent(CheckTypeDO::getCallingColumn, reqVO.getCallingColumn())
                .eqIfPresent(CheckTypeDO::getDisplayBarcode, reqVO.getDisplayBarcode())
                .eqIfPresent(CheckTypeDO::getExpenseRecognition, reqVO.getExpenseRecognition())
                .eqIfPresent(CheckTypeDO::getTimeslotBookNum, reqVO.getTimeslotBookNum())
                .eqIfPresent(CheckTypeDO::getTimeslotReservedNum, reqVO.getTimeslotReservedNum())
                .eqIfPresent(CheckTypeDO::getAffinityCheckTypes, reqVO.getAffinityCheckTypes())
                .orderByDesc(CheckTypeDO::getId));
    }

    default PageResult<CheckTypeDO> selectPageForCallingScreen(CheckTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CheckTypeDO>()
                .likeIfPresent(CheckTypeDO::getName, reqVO.getName())
                .eqIfPresent(CheckTypeDO::getValue, reqVO.getValue())
                .eqIfPresent(CheckTypeDO::getReadyNum, reqVO.getReadyNum())
                .betweenIfPresent(CheckTypeDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CheckTypeDO::getNeedDevReady, reqVO.getNeedDevReady())
                .neIfPresent(CheckTypeDO::getCallingColumn, reqVO.getCallingColumn())
                .eqIfPresent(CheckTypeDO::getDisplayBarcode, reqVO.getDisplayBarcode())
                .eqIfPresent(CheckTypeDO::getExpenseRecognition, reqVO.getExpenseRecognition())
                .eqIfPresent(CheckTypeDO::getTimeslotBookNum, reqVO.getTimeslotBookNum())
                .eqIfPresent(CheckTypeDO::getTimeslotReservedNum, reqVO.getTimeslotReservedNum())
                .eqIfPresent(CheckTypeDO::getAffinityCheckTypes, reqVO.getAffinityCheckTypes())
                .orderByDesc(CheckTypeDO::getId));
    }

    @Select("SELECT * FROM yy_queue.check_type;")
    @Results({
            @Result(property = "displayBarcode", column = "display_barcode", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class),
            @Result(property = "affinityCheckTypes", column = "affinity_check_types", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
    })
    List<CheckTypeDO> simpleCheckTypeList();

    @Select("SELECT * FROM yy_queue.check_type where value = #{checkTypeCode} limit 1;")
    @Results({
            @Result(property = "displayBarcode", column = "display_barcode", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class),
            @Result(property = "affinityCheckTypes", column = "affinity_check_types", typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler.class)
    })
    CheckTypeDO getCheckTypeByValue(@Param("checkTypeCode") Integer checkTypeCode);
}
